﻿Imports System.Math
Public Class CirPoint
    Inherits Points
    Public T, L, E, q As Double
    Public ZY, YZ As New Points
    Public QZ As New Points
    Public startPoint, JD, endPoint As Points
    '转折角
    Public alpha As Double
    '是否是右转折角的标志，默认是右转折角
    Public flag As Boolean = True
    '
    Public alpha1, alpha2 As Double

    Public Sub cal(startP As Points, JDP As Points, endP As Points)
        startPoint = startP
        endPoint = endP
        JD = JDP
        Dim a1, a2 As Double
        a1 = getAzimuth(startPoint, JD)
        a2 = getAzimuth(JD, endPoint)
        alpha = a2 - a1
        If alpha < 0 Then
            alpha = Abs(alpha)
            flag = False
        End If
        alpha1 = a1
        alpha2 = getAzimuth(endPoint, JD)
        ZY.name = "ZY" : YZ.name = "YZ" : QZ.name = "QZ"
        JD.name = "JD"
        ZY.isZD = True : YZ.isZD = True : QZ.isZD = True
        JD.isZD = False
        ZY.pType = "YQX" : YZ.pType = "YQX" : QZ.pType = "YQX"
        JD.pType = "JD"

        JD.k = getKil(startPoint, endPoint) + startPoint.k

        getCirFactor()
        getZDKil()
        getZDCoor()
    End Sub

    Public Sub getCirFactor()
        T = JD.R * Tan(alpha / 2)
        L = JD.R * alpha
        E = JD.R * (1 / Cos(alpha / 2) - 1)
        q = 2 * T - L
    End Sub
    Public Sub getZDKil()
        JD.k = getKil(startPoint, JD)
        ZY.k = JD.k - T
        QZ.k = ZY.k + L / 2
        YZ.k = ZY.k + L
    End Sub
    Public Sub getZDCoor()
        ZY.x = JD.x - T * Cos(alpha1)
        ZY.y = JD.y - T * Sin(alpha1)
        YZ.x = JD.x - T * Cos(alpha2)
        YZ.y = JD.y - T * Sin(alpha2)
        Dim point As Points = getCoor(ZY.k + L / 2, QZ)
        QZ.x = point.x
        QZ.y = point.y
    End Sub
    Public Function getCoor(k As Double, point As Points)
        '独立坐标的计算
        Dim L1 As Double
        Dim phi, x1, y1 As Double
        If k <= QZ.k Then
            L1 = k - ZY.k
        Else
            L1 = YZ.k - k
        End If
        phi = L1 / JD.R

        x1 = JD.R * Sin(phi)
        y1 = JD.R * (1 - Cos(phi))

        '路线坐标的计算
        If flag Then
            If k <= QZ.k Then
                point.x = ZY.x + x1 * Cos(alpha1) - y1 * Sin(alpha1)
                point.y = ZY.y + x1 * Sin(alpha1) + y1 * Cos(alpha1)
            Else
                point.x = YZ.x + x1 * Cos(alpha2) + y1 * Sin(alpha2)
                point.y = YZ.y + x1 * Sin(alpha2) - y1 * Cos(alpha2)
            End If
        Else
            If k <= QZ.k Then
                point.x = ZY.x + x1 * Cos(alpha1) + y1 * Sin(alpha1)
                point.y = ZY.y + x1 * Sin(alpha1) - y1 * Cos(alpha1)
            Else
                point.x = YZ.x + x1 * Cos(alpha2) - y1 * Sin(alpha2)
                point.y = YZ.y + x1 * Sin(alpha2) + y1 * Cos(alpha2)
            End If
        End If

        Return point
    End Function
End Class
